<template>
    <div class="programModify">
        
        <el-form 
            ref="ruleForm" 
            label-width="100px"
            :model="ruleForm">


            <el-form-item label="小程序名称">
                <el-select v-model="ruleForm.appid" placeholder="请选择小程序名称"  @change="handleChange">
                    <el-option :label=item.appname :value=item.appid v-for="(item,index) in options" :key="index">{{item.appname}}{{item.appid}}</el-option>
                </el-select>
            </el-form-item>

            <el-form-item label="小程序名称">
                <el-select v-model="ruleForm.optionValue" multiple placeholder="请选择" @change="handleChange1">
                    <el-option
                    v-for="item in option"
                    :key="item.id"
                    :label="item.name"
                    :value=item.id>
                    {{item.name}}{{item.id}}
                    </el-option>
                </el-select>
            </el-form-item>

           


        </el-form>
       <el-button @click="submitForm('ruleForm')" size="medium" class="addSubimit">提交</el-button>
    </div>
</template>
<script>
import { AddData,getChannel } from '@/assets/js'
export default {
    data(){
        return {
            option:[],
            AID:'',//当前选择小程序的ID
            BID:[],
            submitID:[],//当前选择的分类
            options:[],
            ruleForm:{
                appid:'',
                optionValue:""
            }
        }
    },
    mounted:function(){
        getChannel(this)
    },
    methods:{
        handleChange1(e){//选择分类
            this.BID = e
        },
        handleChange(e){//选择小程序
            this.AID = e;
            this.$axios.getAddressJson('/information/getType',{appid:e})
            .then((res)=>{
                this.option = res.data.data;
                if(this.BID.length>=1){//如果有数据
                    this.BID.map((item,index)=>{
                        this.submitID.push(item)
                    })
                    this.BID = []
                    this.ruleForm.optionValue = []
                    console.log('清空一次BID')
                }
            })
        },
        submitForm:function(e){//点击提交
            let A = '';
            this.BID.map((item,index)=>{
                this.submitID.push(this.AID+'_'+item)
            })
            this.submitID.map((item,index)=>{
                A = A+','+item
            })
            this.BID = [];
            this.ruleForm.optionValue = []
            this.submitID = [];
            var data = {
                id:this.id,
                spdata:A.substr(1)
            }
            console.log(data)
            this.$axios.getAddressJson('information/morePublish',data).then((res)=>{
                // console.log(res)
                if(res.data.code==1){
                    this.$notify({
                        title:res.data.message,
                        type: 'success'
                    });
                }else{
                    this.$notify.error({
                        title: res.data.message,
                    });
                }
            })
        }
    },
    props:['id']
}
</script>